package com.cskaoyan.controller.stage;

import com.cskaoyan.mapper.AftersaleMapper;
import com.cskaoyan.model.Aftersale;
import com.cskaoyan.model.bo.AftersaleBO;
import com.cskaoyan.model.vo.BaseRespVO;
import com.cskaoyan.model.vo.ExceptionVO;
import com.cskaoyan.model.vo.WxDetailVO;
import com.cskaoyan.service.AftersaleService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description：TODO 申请售后服务
 * @author     ：huzhouming
 * @date       ：2022/5/11 2:37
 */
@RestController
@RequestMapping("wx/aftersale")
public class WxAftersaleController {
    @Autowired
    AftersaleService aftersaleService;

    @PostMapping("submit")
    /**
     * @author: huzhouming
     * @description: TODO 申请售后
     * @date: 2022/5/11
     * @param aftersale
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public ExceptionVO submit(@RequestBody AftersaleBO aftersaleBO){
        Subject subject = SecurityUtils.getSubject();
        if (!subject.isAuthenticated()) {
            return ExceptionVO.error(501, "请先登录");
        }
       aftersaleService.insertAftersale(aftersaleBO);
       return BaseRespVO.ok(null);
    }

    @GetMapping("detail")
    /**
     * @author: huzhouming
     * @description: TODO 返回售后细节
     * @date: 2022/5/11
     * @param orderId
     * @return com.cskaoyan.model.vo.BaseRespVO
     */
    public ExceptionVO detail(Integer orderId){
        Subject subject = SecurityUtils.getSubject();
        if (!subject.isAuthenticated()) {
            return ExceptionVO.error(501, "请先登录");
        }
        WxDetailVO wxDetailVO = aftersaleService.getDetail(orderId);
        return BaseRespVO.ok(wxDetailVO);
    }
}
